import time
import urllib.request

import redis

mall_pass_id_key = "PDDMMS_PASSID_COLLECTION_HASH"

# 创建连接池
# pool = redis.ConnectionPool(host="127.0.0.1", port=6379, decode_responses=True)
pool = redis.ConnectionPool(host='172.16.0.15', port='6379', db=10, password='20A3NBVJnWZtNzxumYOz')
# 创建链接对象
redis_client = redis.Redis(connection_pool=pool)

mall_id = 1242420
pass_id = "pass_40"

# redis_client.hset(key, mall_id, pass_id)

#result = redis_client.hkeys(key)

# print(result)


# def get_mall_id():
#     """ 获取店铺id和pass_id"""
#     url = 'http://47.107.76.156/api/open/pddmms/admalls/'
#     headers = {"username": 'dianba.main', "password": "sVqk34j2U82nXnhYPDx8nwdUHW693Gdr",
#                'Accept': "application/vnd.ddgj.v2+json"}
#     request_url = urllib.request.Request(url=url, headers=headers)
#     response = urllib.request.urlopen(request_url)
#     mall_id_dict = eval(response.read().decode("utf-8"))
#     for key, value in mall_id_dict.items():
#         print(value['mallId'],  value['passId'])
#         redis_client.hset(mall_pass_id_key, value['mallId'], value['passId'])
# get_mall_id()

# for i in redis_client.hkeys(mall_pass_id_key):
#     result = redis_client.hget(mall_pass_id_key, str(i))
#     print(i, result)

print("\u7b2c\u4e09\u7ea7\u5206\u7c7b\u6210\u529f mall_id")